package com.htht.smartschool.action.askforleave;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.askforleave.TLeave;
import com.htht.smartschool.service.askforleave.LeaveService;
import com.htht.smartschool.util.system.GsonUtils;

public class LeaveAction extends BaseAction{

	@SuppressWarnings("rawtypes")
	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		LeaveService leaveService = new LeaveService();
		boolean flag = false;
		TLeave tleave = (TLeave) GsonUtils.getInstance().fromJson(pd.getData(), TLeave.class);
		if(pd.getCmd().equalsIgnoreCase("add")){
			Date now = new Date();
			tleave.setCreatetime((now.getTime())/1000);
			TLeave leave = leaveService.add(tleave);
			if(leave != null){
				flag = true;
				obj.setData(leave);
			}else{
				obj.setData("请假失败！");
			}
		}
		else if(pd.getCmd().equalsIgnoreCase("update")){
			TLeave leave = leaveService.update(tleave);
			if(leave != null){
				flag = true;
				obj.setData(leave);
			}else{
				obj.setData("修改失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("delete")){
			boolean result = leaveService.delete(tleave);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("get")){
			List<TLeave> list = leaveService.select(tleave);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getBypage")){
			Map result = leaveService.selectBypage(tleave);
			if(result != null){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("agreeLeave")){
			boolean result = leaveService.agreeLeave(tleave.getId(),tleave.getFlag(),tleave.getRemark());
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("审批出错！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("teacherGetLeave")){
			List<TLeave> list = leaveService.teacherGetLeave(tleave);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查无数据！");
			}
		}
		return flag;
	} 
}
